<?php 
require_once("Config.php");
  $messageFlag = '0';
if(isset($_GET['delid'])){
  $sql = 'delete from news where id='.$_GET['delid'];
  if(mysql_query($sql)){
    
    $sessiongMessage = 'The news story was deleted!';
  }else{
    $sessionMessage = 'Delete news failure,try again or ask for support from website administrator';
  }
  
  $messageFlag = '1';
    
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />



    <title>
      Welcome!
    </title>
    <link href="css/admin-common.css" rel="stylesheet" type="text/css">
   <link type="text/css" href="css/ui-lightness/jquery-ui-1.7.3.custom.css" rel="stylesheet" /> 
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.7.3.custom.min.js"></script>

  
  </head>
  <script type="text/javascript">
    var app={
      init: function() {
      
      
      },
    
      confirmDel:function(delId){
       $('#confirmDelDlg').dialog({
          bgiframe: true,
          modal: true,
          draggable:false,
          autoOpen:false,
          width:300,

          buttons: {
            'No': function() {
              
                $(this).dialog('close');
            },

            'Yes': function() {
             document.location.replace('?delid='+delId);
            }

          }
        });
         $('#confirmDelDlg').dialog('open');
        
      }

    }
  </script>
  <body>
  <div id='confirmDelDlg' style='display:none'>
    Are you sure you want to delete this news story?
  </div>
   <?php 
    $resultCount = mysql_num_rows(mysql_query('select id from news where newsType=0'));
    $pageSize=8;
    $currentPage =isset($_GET['page'])?intval($_GET['page']):1; 
    $pageCount = ceil($resultCount/$pageSize);   
    
    if($currentPage>$pageSize||$currentPage==0){
      echo 'Could not found the page.';
      exit();
    }
    $offset=($currentPage-1)*$pageSize;
    $info=mysql_query("select * from news where newsType=0 limit $offset,$pageSize"); 
  ?>
     <!--Last scrip-->
    
    <h3>News Management</h3>
    <hr/>
    <p>
      <label>
        <strong><a href="news_addForm.php">+Add</a></strong>
      </label>
    </p>
    <table border="0" cellspacing="0" cellpadding="0" class="_table">
      <thead>
        <tr>
          <td>Id</td>
          <td>title</td>
          <td>Created Time</td>
          <td>Operations</td>
        </tr>
      </thead>
      <tbody>
      <?php 
        while($row=mysql_fetch_array($info)){
      ?>
        <tr>
          <td><?php echo $row['id'] ?></td>
          <td style='text-align:left'><strong title='<?php echo $row['outline']?>'><?php echo $row['title'] ?></strong></td>
          <td><?php echo $row['createTime'] ?></td>
        
          <td><label>[<a href="news_editForm.php?id=<?php echo $row['id']?>">Edit</a>]</label>&nbsp;<label>[<a href="javascript:app.confirmDel('<?php echo $row['id'] ?>')">Delete</a>]</label> </td>
        </tr>
        
         <?php
        }
          ?>
       
      </tbody>
    </table>
   <p class="pagingWrapper">
   <?php 
   //first
   if($currentPage>1){
     echo '<label><a href="?page=1">First</a></label> | ';
   }else{
     echo '<label>First</label> | ';
   }
      
    // prvious
    if($currentPage>1){
      echo ('<label><a href="?page='.($currentPage-1).'">Prev</a></label> |');
    }else{
      echo '<label>Prev</label> | ';
    } 
  
    //next 
    if($currentPage<$pageCount){
      echo ('<label><a href="?page='.($currentPage+1).'">Next</a></label> |');
    }
    else{
      echo '<label>Next</label> | ';
    }
  //last
  if($pageCount>1&&$currentPage<$pageCount){
    echo ('<label><a href="?page='.$pageCount.'">Last</a></label> |');
    
  }else{
    
     echo '<label>Last</label> | ';
  }
  
     ?>
      
      
     
     <label> &nbsp;(<?php echo $currentPage.'/'.$pageCount?> <strong>Pgs</strong>)</label>
     <label> &nbsp;to Pg<input type="text" class="pagingBox"/><label></label>
     <label><input type="button" value="go"/></label>
   </p>
    
  </body>
 
</html>
 <script type="text/javascript" src="js/common.js"></script>